
#ifndef GCOMPILER_HEADER_GCOMPILER_H
#define	GCOMPILER_HEADER_GCOMPILER_H

#include "GMachine.h"

#include <cassert>

namespace GCompiler
{
	using namespace GMachine;
	using namespace GMachine::Regname;
	
	class Assembler
	{
	public:	
		void rmov(const TRR& a1, const TRR& a2)
		{
			assert(m_buffersize - m_codelength >= TraitsOfCode<Codename::rmov>::codesize);

			char * ptr = m_codebuffer + m_codelength;
			ptr[0] = Codename::rmov;	
			ptr[1] = a1.regid; 
			ptr[2] = a2.regid;
			m_codelength += TraitsOfCode<Codename::rmov>::codesize;
		}
	private:
		char *	m_codebuffer;
		int		m_codelength;
		int		m_buffersize;
	};
}

#endif	//ifndef GCOMPILER_HEADER_GCOMPILER_H



/*
	Assembler<GCompiler::streaming> vmioasm;
	Assembler<GCompiler::buffered> vmbfasm;

	vmioasm.Init();
	vmioasm.SetIORoutine(routine);
	vmioasm::function<V1R, V1R> fun;
	fun.push(C0);
	fun.comp(C0, arg0, arg1);
	fun.call<C0>();   (C0);
	fun.rpop(C0);
	vmioasm.StoreSymbol(fun);
	vmioasm.rmov(FA0, FB0);
	vmioasm.Flush();

	
	struct R { typedef int RRRRRR; }

	template <typename T>
	call(R0<T>::Type)
	{
		typedef T::RRRRRR NO_USE;
		typedef
		trait<T>::id
	};

	
	template<T>
	struct R0 {
		typedef T::rmov Type;
	};
	vmbfasm.GetBuffer(&codebuf, &size);



	enum CompilerMode {	streaming, buffered	};

	template<int mode> class Assembler;

	template<> class Assembler<GCompiler::streaming>
	{
	public:
		Assembler():m_outroutine(0), m_callbackdt(0)
		{

		}

	public:
		void rmov(const TRR& a1, const TRR& a2)
		{
			assert(m_outroutine);

			char buf[TraitsOfCode<Codename::rmov>::codesize] = 
			{
				Codename::rmov,
				a1.regid,
				a2.regid
			};

			m_outroutine(buf, sizeof(buf), m_callbackdt);
		}
	private:
		void (*m_outroutine)(char *, int, void *);
		void * m_callbackdt;
	};

*/